
import javax.swing.*;

import java.awt.event.*;

public class MyMouse extends JFrame {

    public JLabel jl = new JLabel("鼠标暂无操作");

    public MyMouse() {

        setBounds(100, 100, 350, 80);

//        getContentPane().add("South", jl);

        addMouseListener(new MouseListener() {

            public void mouseClicked(MouseEvent arg0) {
                System.out.println(1);
                jl.setText("鼠标在界面中单击了" + jl.getText() + arg0.getClickCount()

                        + "次");

            }

            public void mouseEntered(MouseEvent arg0) {

                jl.setText("鼠标进入了窗体界面");

            }

            public void mouseExited(MouseEvent arg0) {

                jl.setText("鼠标离开了窗体界面");

            }

            public void mousePressed(MouseEvent arg0) {

                jl.setText("鼠标在窗体界面中按下了键" + arg0.getButton());

            }

            public void mouseReleased(MouseEvent arg0) {

                jl.setText("鼠标在窗体界面中释放了键" + arg0.getButton());

            }

        });

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }

    public static void main(String[] args) {

        MyMouse test = new MyMouse();

        test.setVisible(true);

    }

}

